package com.blockmeta.bbs.businesslibrary.launch;


import com.blockmeta.bbs.baselibrary.base.app.BaseApp;
import com.blockmeta.bbs.businesslibrary.websocket.ConnectCenter;
import com.blockmeta.bbs.businesslibrary.websocket.ConnectInfo;

import java.util.HashMap;
import java.util.Map;


public class ServerYMAL implements IBaseYMAL
{
	private static String FC_CLOSE = null;
	public static final String KEY_IP = "IP";
	public static final String KEY_PORT = "PORT";


	@Override
	public Map<String, Object> parser(String content, String env)
	{
		final YamlParser yml = new YamlParser();
		yml.load(content);

		final String strKey = "ENV," + env + ",";

//		int NUMBER_OF_CORES = Runtime.getRuntime().availableProcessors();
//		int KEEP_ALIVE_TIME = 1;
//		TimeUnit KEEP_ALIVE_TIME_UNIT = TimeUnit.SECONDS;
//		BlockingQueue<Runnable> taskQueue = new LinkedBlockingQueue<Runnable>();
//		ExecutorService executorService = new ThreadPoolExecutor(NUMBER_OF_CORES, NUMBER_OF_CORES*2, KEEP_ALIVE_TIME, KEEP_ALIVE_TIME_UNIT,
//			taskQueue);

		BaseApp.runOnUiThread(new Runnable()
		{
			@Override
			public void run()
			{
				// Quote Server



				ConnectInfo quote = getInfo(yml, strKey);
				if(quote == null)return;
				ConnectCenter.getConnectCenter().initAppServer(
								"coin", quote);
				ConnectCenter.getConnectCenter().onConnectCreate();
			}

		});

		return new HashMap<String, Object>();
	}


	protected ConnectInfo getInfo(YamlParser yml, String key)
	{
		Object obj = yml.getValue(key + "," + KEY_IP);
		if (obj == null || obj.toString().length() == 0)
		{
			return null;
		}

		String ip = obj.toString();
		int port = Integer.valueOf(yml.getValue(key + "," + KEY_PORT).toString());

		return new ConnectInfo("", ip, port);
	}
}